package com.blog.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.blog.dao.BlogDAO;
import com.blog.domain.Blog;
import com.blog.service.BlogService;

@Controller
public class HomeController {
	
	@Autowired
	private BlogService blogService;
	
	@Autowired
	private BlogDAO blogDAO;
	
	public BlogDAO getBlogDAO() {
		return blogDAO;
	}

	public void setBlogDAO(BlogDAO blogDAO) {
		this.blogDAO = blogDAO;
	}

	public BlogService getBlogService() {
		return blogService;
	}

	public void setBlogService(BlogService blogService) {
		this.blogService = blogService;
	}

	@RequestMapping("/")
	public String index(ModelMap model){
		List<Blog> blog_list = blogDAO.executeQuery("from Blog order by id desc", 0, 10);
		List<Blog> hot_list = blogDAO.executeQuery("from Blog order by reader desc", 0, 10);
		model.addAttribute("blog_list", blog_list);
		model.addAttribute("hot_list", hot_list);
		return "baseLayout";
	}
	
	@RequestMapping("/about")
	public String about() { 
		return "about";
	}
	
	@RequestMapping("/tutorial")
	public String tutorial() { 
		return "tutorial";
	}
	
	@RequestMapping("/download/tools")
	public String tools() { 
		return "tools";
	}
	
	@RequestMapping("/download/sourcefile")
	public String sourcefile() { 
		return "sourcefile";
	}
	
	@RequestMapping("/contact")
	public String contact() {
		return "contact";
	}
	 
	
	
}

